
include( "duplicator_gui_button.lua")

local PANEL = {}

PANEL.VoteName = "none"
PANEL.MaterialName = "exclamation"

/*---------------------------------------------------------
   Name: 
---------------------------------------------------------*/
function PANEL:Init()

	self.NewName = vgui.Create( "TextEntry", self )
	self.NewName:SetKeyboardInputEnabled( true )
	self.NewName:SetEnabled( true )
	
	self.StoreButton = vgui.Create( "Button", self )
	self.StoreButton:SetText( "#Store" )
	self.StoreButton.DoClick = function() self.OnStore( self ) end
	
	self.List = vgui.Create( "PanelList", self )
	self.List:SetSpacing( 1 )
	
	self.DuplicateList = {}
	
	self:ApplySchemeSettings()
	
end

/*---------------------------------------------------------
   Name: PerformLayout
---------------------------------------------------------*/
function PANEL:OnStore()
	
	local Name = tostring( self.NewName:GetValue() )
	Name:gsub( "\"", "'" )
	LocalPlayer():ConCommand( "tool_duplicator_store \"" .. Name .. "\"" )
	
end

/*---------------------------------------------------------
   Name: PerformLayout
---------------------------------------------------------*/
function PANEL:ApplySchemeSettings()
	
end

/*---------------------------------------------------------
   Name: PerformLayout
---------------------------------------------------------*/
function PANEL:PerformLayout()	

	self.StoreButton:SizeToContents()
	
	local Border = 10
	local Tall = 400
	local iTop = Tall - self.StoreButton:GetTall() - Border

	self.NewName:SetSize( self:GetWide() - self.StoreButton:GetWide() - Border*3, self.StoreButton:GetTall() );
	self.NewName:SetPos( Border, iTop )
	
	self.StoreButton:SetPos( Border + self.NewName:GetWide() + Border, iTop )
	
	self.List:SetPos( Border, Border )
	self.List:SetSize( self:GetWide() - Border * 2, iTop - Border*2 )
	
	self:SetSize( self:GetWide(), Tall )
	

end

/*---------------------------------------------------------
   Name: Paint
---------------------------------------------------------*/
function PANEL:Paint()

	local bgColor = Color( 130, 130, 130, 255 )
	draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), bgColor )
	
	return true

end

/*---------------------------------------------------------
   Name: Clear
---------------------------------------------------------*/
function PANEL:Clear( )

	self.DuplicateList = {}

end

/*---------------------------------------------------------
   Name: Populate
---------------------------------------------------------*/
function PANEL:Add( id, name )

	self.DuplicateList[ id ] = name

end

/*---------------------------------------------------------
   Name: Populate
---------------------------------------------------------*/
function PANEL:Populate()

	self.List:Clear()

	for k, v in pairs( self.DuplicateList ) do
	
		local Button = vgui.Create( "DuplicatorButton", self )
		Button:SetItemText( v )
		Button:SetID( k )
		self.List:AddItem( Button )
	
	end
	
end


vgui.Register( "DuplicatorControl", PANEL, "Panel" )

